#include<bits/stdc++.h>
#define int long long
using namespace std;
const int N=5e5+5,inf=1e18,mod=1e9+7;
inline char gc(){
	static char buf[1000000],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,1000000,stdin),p1==p2)?EOF:*p1++;
}
inline int read(){
	int sum=0,f=0;
	char ch=gc();
	for(;!isdigit(ch);ch=gc())f|=(ch=='-');
	for(;isdigit(ch);ch=gc()) sum=((sum<<1)+(sum<<3)+(ch^48));
	return f?-sum:sum;
}
int n,k,a[N],pw[N],f[N],ans;

int tp;
pair<int,int> s[N];

#define ls (x<<1)
#define rs (x<<1|1)
#define mid (l+r>>1)

int minn[N<<2],laz[N<<2];

void pushup(int x){
	minn[x]=min(minn[ls],minn[rs]);
} 
void down(int x,int k){
	minn[x]+=k;
	laz[x]+=k;
}
void pushdown(int x){
	down(ls,laz[x]);
	down(rs,laz[x]);
	laz[x]=0;
}
void modify(int x,int l,int r,int p,int k){
	if(l==r){
		minn[x]=k;
		return;
	}
	pushdown(x);
	if(p<=mid) modify(ls,l,mid,p,k);
	else modify(rs,mid+1,r,p,k);
	pushup(x);
}
void update(int x,int l,int r,int L,int R,int k){
	if(l>=L&&r<=R){
		down(x,k);
		return;
	}
	pushdown(x);
	if(L<=mid) update(ls,l,mid,L,R,k);
	if(R>mid) update(rs,mid+1,r,L,R,k);
	pushup(x);
}
int query(int x,int l,int r,int L,int R){
	if(l>=L&&r<=R) return minn[x];
	pushdown(x);
	int res=inf;
	if(L<=mid) res=min(res,query(ls,l,mid,L,R));
	if(R>mid) res=min(res,query(rs,mid+1,r,L,R));
	return res;
}

signed main(){
	freopen("knight.in","r",stdin);
	freopen("knight.out","w",stdout);
	n=read(),k=read(),pw[0]=1;
	for(int i=1;i<=n;i++) a[i]=read(),pw[i]=pw[i-1]*23%mod;
	for(int i=1;i<=n;i++){
		while(tp&&s[tp].first<a[i]){
			int pos=s[tp--].second;
			update(1,1,n,s[tp].second+1,pos,a[i]-s[tp+1].first);
		}
		s[++tp]={a[i],i};
		modify(1,1,n,i,f[i-1]+a[i]);
		f[i]=query(1,1,n,max(1ll,i-k+1),i);
		ans=(ans+f[i]*pw[n-i]%mod)%mod;
	}
	printf("%lld",ans);
	return 0;
}
